
package com.admissions.adapter;

import java.util.ArrayList;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.admissions.R;
import com.admissions.model.CauHoi;

/**
 * @author Bkav-DangNVb
 *
 */
public class AllThreadsAdapter extends BaseAdapter {
    private Context mContext;

    ArrayList<CauHoi> questions = new ArrayList<CauHoi>();

    public AllThreadsAdapter(Context context, ArrayList<CauHoi> questions) {
        mContext = context;
        this.questions = questions;
    }

    @Override
    public int getCount() {
        return questions.size();
    }

    @Override
    public Object getItem(int position) {
        return questions.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        if (convertView == null) {
            LayoutInflater inflater = (LayoutInflater) mContext
                    .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            convertView = inflater.inflate(R.layout.single_question_layout, null, false);
        }

        TextView item = (TextView) convertView.findViewById(R.id.item);
        TextView content = (TextView) convertView.findViewById(R.id.item_content);
        TextView answer_a = (TextView) convertView.findViewById(R.id.answer_a_content);
        TextView answer_b = (TextView) convertView.findViewById(R.id.answer_b_content);
        TextView answer_c = (TextView) convertView.findViewById(R.id.answer_c_content);
        TextView answer_d = (TextView) convertView.findViewById(R.id.answer_d_content);

        CauHoi cauhoi = questions.get(position);

        item.setText("Câu hỏi " + cauhoi.item + ":");
        content.setText(cauhoi.content);
        answer_a.setText(cauhoi.dapans.get(0).content);
        answer_b.setText(cauhoi.dapans.get(1).content);
        answer_c.setText(cauhoi.dapans.get(2).content);
        answer_d.setText(cauhoi.dapans.get(3).content);

        convertView.setTag(cauhoi);

        return convertView;
    }
}
